<template>
	<view class="page">
		<view>
			<view class="item-back" @click="gotoPage('/pages/user/my-account/selectBack/selectBack')">
				<view class="back-select" >
					<text class="backSelect" v-if=" bank.type == '' ">请选择提现类型</text>
					<view>
						<!-- <image class="back-logo" src="../../../../static/app/jiaotou.png"></image> -->
						<!-- <image class="back-logo" :src="bank.icon"></image> -->
						<image class="back-logo" v-if="bank.type == 3" src="../../../../static/bank.png"></image>
						<image class="back-logo" v-if="bank.type == 2" src="../../../../static/zfb1.png"></image>
						<image class="back-logo" v-if="bank.type == 1" src="../../../../static/wx1.png"></image>
					</view>
					<view class="back-describe">
						
						<text class="back-name" v-if=" bank.type == 1 ">微信</text>
						<text class="back-name"  v-if=" bank.type == 2 ">支付宝</text>
						<text class="back-name"  v-if=" bank.type == 3 ">{{bank.name}}</text>
						<text class="back-tag">{{bank.binding}}</text>
					</view>
				</view>
				<image class="back-select-next" src="../../../../static/jiantou3.png"></image>
			</view>
			<!-- <view class="item-cardBox">
				<view class="item-cardSel">
					<picker @change="selectType" range-key="type_name" :range="bankType" :value="index">
						<input type="text" disabled="" v-model="type_name" placeholder="请选择卡类型" />
					</picker>
				</view>
				<view class="item-cardSel item-cardNum">
					<input type="text" placeholder="请输入卡号" />			
				</view>
			</view> -->
			
			<view class="item-withdraw">
				<view class="item-name">提现金额</view>
				<view class="item-price">
					<text>&yen</text>
					<input type="digit" focus="" v-model="price" />
				</view>
				<view class="line"></view>
				<view class="balance">
					<view>账户余额 {{nowprice}} 元</view>
				</view>
			</view>
			<view class="discribe">
				<text>备注:</text>
				<input type="text" v-model="bank_discribe"/>
			</view>
			<view class="confirm" @click="$noMultipleClicks(fromSubmit)">
				<text>确   定</text>
			</view>
			<!-- <view class="confirm" @click="showIntegral">
				<text>确   定</text>
			</view> 
			<view class="developing" v-if="developing">
				正在开发当中，请尽情期待... ...
			</view> -->
			<!-- <view class="closeIntegral" @click="closeIntegral()" v-if="developing">确定</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bank: {
					name: '',
					icon: '',
					binding: '',
					id: '',
					type:'',
					bank_code:'',
					// name: '桂林银行',
					// icon: '../../../../static/guilLogo.jpg',
					// binding: '尾号6666储蓄卡',
					// id: '-1',
				},
				price:'',//提现的金额
				nowprice:'',//账户余额
				developing:false,
				timer:null,
				bankType:[],
				type_name:'',
				index: 0,
				bank_discribe:'',//备注
				noClick:true,
			};
		},
		onLoad(option) {
			//this.getBankType();
			this.getData();
			if(option.select == 1 ) {
				console.log(option)
				this.bank.name = JSON.parse(option.bank).name;
				this.bank.type = JSON.parse(option.bank).bank_type;
				//console.log(this.bank.name)
				this.bank.bank_code = JSON.parse(option.bank).bank_code;
				this.bank.binding = JSON.parse(option.bank).thumb;
				this.bank.id = JSON.parse(option.bank).id;
			}						
		},
		methods: {	
			/*获取余额数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get(
					'user.index/my_money',
					{
						
					},
					function(data) {
						//console.log(data);
						self.tableData = data.data.list;
						self.nowprice = self.tableData.balance;
						console.log(self.nowprice)
						//this.loading = true;
						uni.hideLoading();
					}
				);
			},
			/* 获取类型 */
			getBankType() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('home/bank_type', {}, function(res) {
					//console.log(res);
					self.bankType = res.data.type_list;
					uni.hideLoading();
				});
			},
			/*卡类型选择 */
			selectType: function(e) {
				console.log(e);
				let driverId = e.detail.value;
				let type = this.bankType[driverId];
				this.type_name = type.type_name;
				this.type_id = type.id;//卡类型id
				console.log(this.type_id)
			},
			closeIntegral() {
				this.developing = false
				if (this.timer) {
					clearTimeout(this.timer);
					this.timer = null;
				}
			},
			showIntegral() {
				this.developing = true;
				this.timer = setTimeout(() => {
					this.developing = false
				}, 3000);
			},
			fromSubmit(){
				let self = this;
				let formdata = {};
				
				if(self.bank.type == ''){
					uni.showModal({
						title:'请选择提现类型',
						duration:1000,
						icon:'none'
					});
					return;
				}
				if (self.price == '') {
					uni.showToast({
						title: '请请输入金额',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}
				// if (self.price > self.nowprice) {
				// 	uni.showToast({
				// 		title: '余额不足',
				// 		duration: 1000,
				// 		icon: 'none'
				// 	});
				// 	return false;
				// }
				//formdata.name = self.bank.name;
				//formdata.bank_type = self.bank.type;
				formdata.bank_id = self.bank.id;
				formdata.money = self.price;
				formdata.describe = self.bank_discribe;

				uni.showLoading({
					title: '正在提交'
				});
				self._post(
					'user.index/withdrawal',
					formdata,
					result => {
						// 记录token user_id
						// uni.setStorageSync('token', result.data.token);
						// uni.setStorageSync( 'user_id', result.data.user_id );
						if (result.code == 1) {
							uni.showToast({
								title: '成功！',
								duration: 2000,
								icon: 'none'
							});
							self.gotoPage('/pages/user/caseRecord/caseRecord');
						}
						// 执行回调函数
						// uni.navigateBack();
					},
					false,
					() => {
						uni.hideLoading();
					}
				);
			},
			/*跳转页面*/
			gotoPage(path) {
				let self = this;
				if (path.startsWith('/')) {
					uni.navigateTo({
						url: path
					});
				} else {
					self[path]();
				}
			},
		}
	}
</script>

<style lang="scss">
	@import 'withdraw.scss';

	.item-cardBox,.discribe{
		width: 90%;
		padding: 0 20rpx;
		margin: 0 auto;
		border-radius: 10rpx;
		background-color: #FFFFFF;
		//margin-top: 20rpx;
	}
	.item-cardSel{
		padding: 30rpx 0;
		border-bottom: 2rpx solid #F4F4F4;
	}
	.item-cardNum{
		border-bottom: none;
	}
	.discribe{
		width: 88%;
		padding: 30rpx;
		display: flex;
		align-items: center;
	}
	.discribe text{
		margin-right: 10rpx;
		color: #7d7d7d;
	}
</style>
